package com.jason.platform.supervision.fragment;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import com.hzlj.supervision.changsha.R;
import com.jason.platform.supervision.activity.StatisticsActivity;
import com.jason.platform.supervision.base.Constant;
import com.jason.platform.supervision.beans.Category;
import com.jason.platform.supervision.beans.StatisticsRedressResp;
import com.jason.platform.supervision.beans.TongJiBean;
import com.jason.platform.supervision.task.Task;

/**
 * @ClassName: StatisticsRedressFragment
 * @Description: 矫正对象
 * @Author: Jason.Zhang zhangyujn1989ok@gmail.com
 * @Date: 2015-7-27 16:59:43
 */
public class StatisticsRedressFragment extends BaseFragment {

    private static final String TAG = StatisticsRedressFragment.class.getSimpleName();

    private Category mParentCategory;
    private int mPosition;

    private StatisticsActivity mActivity;

    private TextView mZaiCeTextView,mJieJiaoTextView,mLeiJiTextVeiw,mGuanZhiTextView,mHuanXingTextView,
            mJiaShiTextView,mJianWaiTextView,mBoQuanTextView,mShoujiDingWeiTextView,mBeiDouDingWeiTextView,mXinZengTextView;

    private TextView mDyrjTextView,mDyjjTextView;

    private TongJiBean mTongJiBean;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.i(TAG, "onCreate...");
        mActivity = (StatisticsActivity) getActivity();
        mParentCategory = (Category) tag;
        if (arg1 != null) {
            mPosition = (Integer) arg1;
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        Log.i(TAG, "onCreateView...");
        View view = inflater.inflate(R.layout.fragment_statistics_redress, null, true);
        initWidget(view);
        return view;
    }

    private void initWidget(View view){
        mZaiCeTextView = (TextView) view.findViewById(R.id.redress_zaice);
        mJieJiaoTextView = (TextView) view.findViewById(R.id.redress_jiejiao);
        mLeiJiTextVeiw = (TextView) view.findViewById(R.id.redress_leiji);
        mGuanZhiTextView = (TextView) view.findViewById(R.id.redress_guanzhi);
        mHuanXingTextView = (TextView) view.findViewById(R.id.redress_huanxing);
        mJiaShiTextView = (TextView) view.findViewById(R.id.redress_jiashi);
        mJianWaiTextView = (TextView) view.findViewById(R.id.redress_jianwai);
        mBoQuanTextView = (TextView) view.findViewById(R.id.redress_boquan);
        mShoujiDingWeiTextView = (TextView) view.findViewById(R.id.redress_shoujidingwei);
        mBeiDouDingWeiTextView = (TextView) view.findViewById(R.id.redress_beidoudingwei);
        mXinZengTextView = (TextView) view.findViewById(R.id.redress_xinzeng);

        mDyrjTextView = (TextView) view.findViewById(R.id.redress_dyrj);
        mDyjjTextView = (TextView) view.findViewById(R.id.redress_dyjj);
    }

    private void updateData(){
        if (mTongJiBean == null){
            return;
        }
        mZaiCeTextView.setText(mTongJiBean.getZcrs());
        mJieJiaoTextView.setText(mTongJiBean.getJjrs());
        mLeiJiTextVeiw.setText("0");
        mGuanZhiTextView.setText(mTongJiBean.getGz());
        mHuanXingTextView.setText(mTongJiBean.getHx());
        mJiaShiTextView.setText(mTongJiBean.getJs());
        mJianWaiTextView.setText(mTongJiBean.getJwzx());
        mBoQuanTextView.setText(mTongJiBean.getBq());
        mShoujiDingWeiTextView.setText(mTongJiBean.getSjdw());
        mBeiDouDingWeiTextView.setText(mTongJiBean.getBddw());
        mXinZengTextView.setText(mTongJiBean.getDyrj());

        mDyrjTextView.setText(mTongJiBean.getDyrj());
        mDyjjTextView.setText(mTongJiBean.getDyjj());
    }

    @Override
    public void onResume() {
        super.onResume();
        Log.i(TAG, "onResume...");
    }

    @Override
    public void onFrameResume() {
        super.onFrameResume();
        Log.i(TAG, "onResume...");
    }

    @Override
    public void onDataCallback(Task task) {
        super.onDataCallback(task);
        if (task.type == Constant.Manager.GET_TONGJILIST_LIST){
            if (task.isSuccess) {
                StatisticsRedressResp resp = (StatisticsRedressResp) task.resData;
                mTongJiBean = resp.getValues().get(0);
                updateData();
                setNetInitState(BaseFragment.NetState.INIT_SUCCESS);
            } else {
                Toast.makeText(mActivity, task.rspDesc, Toast.LENGTH_SHORT).show();

                setNetInitState(BaseFragment.NetState.INIT_FAILED);
            }
        }
    }
}
